package com.csii.modules.online.cgform.service.impl;

import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.csii.autocode.entity.ColumnVo;
import com.csii.autocode.entity.MainTableVo;
import com.csii.autocode.entity.SubTableVo;
import com.csii.autocode.entity.TableVo;
import com.csii.autocode.service.impl.CodeGenerateOne;
import com.csii.autocode.service.impl.CodeGenerateOneToMany;
import com.csii.autocode.utils.DbReadTableUtil;
import com.csii.core.api.Result;
import com.csii.core.constant.CommonConstant;
import com.csii.core.constant.enums.CgformEnum;
import com.csii.core.util.*;
import com.csii.modules.online.cgform.enhance.CgformEnhanceJavaInter;
import com.csii.modules.online.cgform.enhance.CgformEnhanceJavaListInter;
import com.csii.modules.online.cgform.entity.*;
import com.csii.modules.online.cgform.mapper.*;
import com.csii.modules.online.cgform.model.OnlCgformModel;
import com.csii.modules.online.cgform.model.OnlFieldModel;
import com.csii.modules.online.cgform.model.OnlGenerateModel;
import com.csii.modules.online.cgform.service.IOnlCgformFieldService;
import com.csii.modules.online.cgform.service.IOnlCgformHeadService;
import com.csii.modules.online.cgform.service.IOnlCgformIndexService;
import com.csii.modules.online.cgform.util.CgformSqlUtil;
import com.csii.modules.online.config.db.DataBaseConfig;
import com.csii.modules.online.config.db.FreemarkerConfig;
import com.csii.modules.online.config.exception.BusinessException;
import com.csii.modules.online.config.exception.DBException;
import com.csii.modules.online.config.service.DbTableHandler;
import com.csii.modules.online.config.util.SqlFreemarkerUtil;
import com.csii.modules.online.config.util.DialectUtil;
import com.csii.modules.system.entity.SysDataSource;
import freemarker.template.TemplateException;
import org.hibernate.HibernateException;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.HttpHeaders;
import org.springframework.http.HttpMethod;
import org.springframework.http.MediaType;
import org.springframework.jdbc.core.JdbcTemplate;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.io.IOException;
import java.io.UnsupportedEncodingException;
import java.net.URLDecoder;
import java.sql.SQLException;
import java.util.*;
import java.util.stream.Collectors;

@Service("onlCgformHeadServiceImpl")
public class OnlCgformHeadServiceImpl extends ServiceImpl<OnlCgformHeadMapper, OnlCgformHead> implements IOnlCgformHeadService {
	private static final Logger LOGGER = LoggerFactory.getLogger(OnlCgformHeadServiceImpl.class);
	@Autowired
	private IOnlCgformFieldService fieldService;
	@Autowired
	private IOnlCgformIndexService indexService;
	@Autowired
	private OnlCgformEnhanceJsMapper onlCgformEnhanceJsMapper;
	@Autowired
	private OnlCgformButtonMapper onlCgformButtonMapper;
	@Autowired
	private OnlCgformEnhanceJavaMapper onlCgformEnhanceJavaMapper;
	@Autowired
	private OnlCgformEnhanceSqlMapper onlCgformEnhanceSqlMapper;
	@Autowired
	private DataBaseConfig dataBaseConfig;
	@Autowired
	private JdbcTemplate jdbcTemplate;
	@Override
	@Transactional(
			rollbackFor = {Exception.class}
	)
	public Result<?> addAll(OnlCgformModel model) {
		String id = UUID.randomUUID().toString().replace("-", "");
		OnlCgformHead onlCgformHead = model.getHead();
		List fields = model.getFields();
		List indexs = model.getIndexs();
		onlCgformHead.setId(id);
		boolean hasTenantId=false;
		for (int var6 = 0; var6 < fields.size(); ++var6) {
			OnlCgformField var7 = (OnlCgformField) fields.get(var6);
			var7.setId((String) null);
			var7.setCgformHeadId(id);
			if (var7.getOrderNum() == null) {
				var7.setOrderNum(var6);
			}
			this.setLength(var7);
			if(var7.getDbFieldName().equalsIgnoreCase("tenant_id"))//判断是否含有租户字段
				hasTenantId=true;
		}
		//增加租户字段
		if(!hasTenantId){
			addTenantFiled(fields);
		}
		Iterator var8 = indexs.iterator();

		while (var8.hasNext()) {
			OnlCgformIndex var9 = (OnlCgformIndex) var8.next();
			var9.setId((String) null);
			var9.setCgformHeadId(id);
		}

		onlCgformHead.setIsDbSynch("N");
		onlCgformHead.setTableVersion(1);
		onlCgformHead.setCopyType(0);
		if (onlCgformHead.getTableType() == 3 && onlCgformHead.getTabOrderNum() == null) {
			onlCgformHead.setTabOrderNum(1);
		}

		super.save(onlCgformHead);
		this.fieldService.saveBatch(fields);
		this.indexService.saveBatch(indexs);
		this.saveRelation(onlCgformHead, fields);
		return Result.ok("添加成功");
	}
	void addTenantFiled(List<OnlCgformField> fields){
		OnlCgformField onlCgformField=new OnlCgformField();
		onlCgformField.setCgformHeadId(fields.get(0).getCgformHeadId());
		onlCgformField.setDbFieldName("tenant_id");
		onlCgformField.setDbFieldTxt("租户");
		onlCgformField.setDbIsKey(0);
		onlCgformField.setDbIsNull(1);
		onlCgformField.setDbType("String");
		onlCgformField.setDbLength(32);
		onlCgformField.setDbPointLength(0);
		onlCgformField.setFieldShowType("text");
		onlCgformField.setFieldLength(120);
		onlCgformField.setFieldMustInput("0");
		onlCgformField.setIsQuery(0);
		onlCgformField.setIsShowForm(0);
		onlCgformField.setIsShowList(0);
		onlCgformField.setIsReadOnly(0);
		onlCgformField.setOrderNum(fields.size());
		onlCgformField.setQueryShowType("text");
		onlCgformField.setSortFlag("0");
		onlCgformField.setQueryConfigFlag("0");
		fields.add(onlCgformField);
	}
	@Override
	@Transactional(
			rollbackFor = {Exception.class}
	)
	public Result<?> editAll(OnlCgformModel model) {
		OnlCgformHead var3 = (OnlCgformHead) super.getById(model.getHead().getId());
		if (var3 == null) {
			return Result.error("未找到对应实体");
		} else {
			String var4 = var3.getIsDbSynch();
			if (CgformSqlUtil.compareHead(var3, model.getHead())) {
				var4 = "N";
			}

			Integer var5 = var3.getTableVersion();
			if (var5 == null) {
				var5 = 1;
			}

			model.getHead().setTableVersion(var5 + 1);
			List<OnlCgformField> fields = model.getFields();
			List<OnlCgformIndex> indexs = model.getIndexs();
			List<OnlCgformField> onlCgformFields = new ArrayList();
			List<OnlCgformField> cgformFields = new ArrayList();
			Iterator var10 = fields.iterator();

			while (var10.hasNext()) {
				OnlCgformField var11 = (OnlCgformField) var10.next();
				String var12 = String.valueOf(var11.getId());
				this.setLength(var11);
				if (!var12.equals("null")) {
					cgformFields.add(var11);
				} else {
					String var13 = "_pk";
					if (!var13.equals(var12)) {
						var11.setId((String) null);
						var11.setCgformHeadId(model.getHead().getId());
						onlCgformFields.add(var11);
					}
				}
			}

			if (onlCgformFields.size() > 0) {
				var4 = "N";
			}

			int var18 = 0;

			Iterator var19 = null;
			OnlCgformField var21;
			for (var19 = cgformFields.iterator(); var19.hasNext(); this.fieldService.updateById(var21)) {
				var21 = (OnlCgformField) var19.next();
				OnlCgformField var23 = (OnlCgformField) this.fieldService.getById(var21.getId());
				boolean var14 = CgformSqlUtil.compareField(var23, var21);
				if (var14) {
					var4 = "N";
				}

				if ((var23.getOrderNum() == null ? 0 : var23.getOrderNum()) > var18) {
					var18 = var23.getOrderNum();
				}
			}

			for (var19 = onlCgformFields.iterator(); var19.hasNext(); this.fieldService.save(var21)) {
				var21 = (OnlCgformField) var19.next();
				if (var21.getOrderNum() == null) {
					++var18;
					var21.setOrderNum(var18);
				}
			}

			List var20 = this.indexService.getCgformIndexsByCgformId(model.getHead().getId());
			ArrayList var22 = new ArrayList();
			ArrayList var24 = new ArrayList();
			Iterator var25 = indexs.iterator();

			OnlCgformIndex var15;
			while (var25.hasNext()) {
				var15 = (OnlCgformIndex) var25.next();
				String var16 = String.valueOf(var15.getId());
				if (var16.length() == 32) {
					var24.add(var15);
				} else {
					var15.setId((String) null);
					var15.setCgformHeadId(model.getHead().getId());
					var22.add(var15);
				}
			}

			var25 = var20.iterator();

			while (var25.hasNext()) {
				var15 = (OnlCgformIndex) var25.next();
				if (!indexs.contains(var15)) {
					var15.setDelFlag(CommonConstant.DEL_FLAG_1);
					var24.add(var15);
					var4 = "N";
				}
			}

			if (var22.size() > 0) {
				var4 = "N";
				this.indexService.saveBatch(var22);
			}

			for (var25 = var24.iterator(); var25.hasNext(); this.indexService.updateById(var15)) {
				var15 = (OnlCgformIndex) var25.next();
				OnlCgformIndex var27 = (OnlCgformIndex) this.indexService.getById(var15.getId());
				boolean var17 = CgformSqlUtil.compareIndex(var27, var15);
				if (var17) {
					var4 = "N";
					var15.setIsDbSynch("N");
				}
			}

			if (model.getDeleteFieldIds().size() > 0) {
				var4 = "N";
				this.fieldService.removeByIds(model.getDeleteFieldIds());
			}

			model.getHead().setIsDbSynch(var4);
			super.updateById(model.getHead());
			this.saveRelation(model.getHead(), fields);
			this.b(model.getHead(), fields);
			return Result.ok("全部修改成功");
		}
	}

	@Override
	public void doDbSynch(String code, String synMethod) throws HibernateException, IOException, TemplateException, SQLException, DBException {
		OnlCgformHead onlCgformHead = this.getById(code);
		if (onlCgformHead == null) {
			throw new DBException("实体配置不存在");
		} else {
			String tableName = onlCgformHead.getTableName();
			LambdaQueryWrapper<OnlCgformField> queryWrapper = new LambdaQueryWrapper();
			queryWrapper.eq(OnlCgformField::getCgformHeadId, code);
			queryWrapper.orderByAsc(OnlCgformField::getOrderNum);
			List cgformFields = this.fieldService.list(queryWrapper);
			FreemarkerConfig freemarkerConfig = new FreemarkerConfig();
			freemarkerConfig.setTableName(tableName);
			freemarkerConfig.setJformPkType(onlCgformHead.getIdType());
			freemarkerConfig.setJformPkSequence(onlCgformHead.getIdSequence());
			freemarkerConfig.setContent(onlCgformHead.getTableTxt());
			freemarkerConfig.setColumns(cgformFields);
			freemarkerConfig.setDbConfig(this.dataBaseConfig);
			//判断同步方式
			if ("normal".equals(synMethod)) {
				long timeMillis = System.currentTimeMillis();
				boolean tableExists = DialectUtil.isTableExists(tableName);
				LOGGER.info("==判断表是否存在消耗时间" + (System.currentTimeMillis() - timeMillis) + "毫秒");
				if (tableExists) {
					SqlFreemarkerUtil cUtil = new SqlFreemarkerUtil();
					List stringList = cUtil.getUpdateSql(freemarkerConfig);
					Iterator iterator = stringList.iterator();
					while (iterator.hasNext()) {
						String sql = (String) iterator.next();
						if (!oConvertUtils.isEmpty(sql) && !oConvertUtils.isEmpty(sql.trim())) {
							jdbcTemplate.update(sql);
						}
					}
					//处理索引
					List<OnlCgformIndex> onlCgformIndexList = this.indexService.list(Wrappers.lambdaQuery(OnlCgformIndex.class).eq(OnlCgformIndex::getCgformHeadId, code));
					for(OnlCgformIndex onlCgformIndex: onlCgformIndexList){
						if(!"N".equals(onlCgformIndex.getIsDbSynch()) && !CommonConstant.DEL_FLAG_1.equals(onlCgformIndex.getDelFlag()))
							continue;
						String indexName = cUtil.countIndex(onlCgformIndex.getIndexName(), tableName);
						if (this.indexService.isExistIndex(indexName)) {
							String dropIndexSql = cUtil.dropIndexs(onlCgformIndex.getIndexName(), tableName);
							try {
								LOGGER.info("删除索引 executeDDL:" + dropIndexSql);
								jdbcTemplate.update(dropIndexSql);
								if (CommonConstant.DEL_FLAG_1.equals(onlCgformIndex.getDelFlag())) {
									this.indexService.removeById(onlCgformIndex.getId());
								}
							} catch (Exception e) {
								LOGGER.error("删除表【" + tableName + "】索引(" + onlCgformIndex.getIndexName() + ")失败!", e);
							}
						} else if (CommonConstant.DEL_FLAG_1.equals(onlCgformIndex.getDelFlag())) {
							this.indexService.removeById(onlCgformIndex.getId());
						}
					}
					/*Iterator iterator1 = onlCgformIndexList.iterator();
					while (true) {
						OnlCgformIndex onlCgformIndex=null;
						do {
							if (!iterator1.hasNext()) {
								break;
							}

							onlCgformIndex = (OnlCgformIndex) iterator1.next();
						} while (!"N".equals(onlCgformIndex.getIsDbSynch()) && !CommonConstant.DEL_FLAG_1.equals(onlCgformIndex.getDelFlag()));

						String indexName = cUtil.countIndex(onlCgformIndex.getIndexName(), tableName);
						if (this.indexService.isExistIndex(indexName)) {
							String dropIndexSql = cUtil.dropIndexs(onlCgformIndex.getIndexName(), tableName);
							try {
								LOGGER.info("删除索引 executeDDL:" + dropIndexSql);
								jdbcTemplate.update(dropIndexSql);
								if (CommonConstant.DEL_FLAG_1.equals(onlCgformIndex.getDelFlag())) {
									this.indexService.removeById(onlCgformIndex.getId());
								}
							} catch (Exception e) {
								LOGGER.error("删除表【" + tableName + "】索引(" + onlCgformIndex.getIndexName() + ")失败!", e);
							}
						} else if (CommonConstant.DEL_FLAG_1.equals(onlCgformIndex.getDelFlag())) {
							this.indexService.removeById(onlCgformIndex.getId());
						}
					}*/
				} else {
					SqlFreemarkerUtil.getCreateSql(freemarkerConfig);
				}
			} else if ("force".equals(synMethod)) {
				DbTableHandler dbTableHandler = DialectUtil.getTableHandle();
				String var9 = dbTableHandler.dropTableSQL(tableName);
				jdbcTemplate.update(var9);
				SqlFreemarkerUtil.getCreateSql(freemarkerConfig);
			}

			this.indexService.createIndex(code, DialectUtil.getDatabaseType(), tableName);
			onlCgformHead.setIsDbSynch("Y");
			this.updateById(onlCgformHead);
		}
	}

	@Override
	public void deleteRecordAndTable(String id) throws DBException, SQLException {
		OnlCgformHead var2 = (OnlCgformHead) this.getById(id);
		if (var2 == null) {
			throw new DBException("实体配置不存在");
		} else {
			long var3 = System.currentTimeMillis();
			boolean var5 = DialectUtil.isTableExists(var2.getTableName());
			LOGGER.info("==判断表是否存在消耗时间 " + (System.currentTimeMillis() - var3) + "毫秒");
			if (var5) {
				String var6 = DialectUtil.getTableHandle().dropTableSQL(var2.getTableName());
				LOGGER.info(" 删除表  executeDDL： " + var6);
				//this.baseMapper.executeDDL(var6);
				jdbcTemplate.update(var6);
			}

			this.baseMapper.deleteById(id);
			this.deleteRelation(var2);
		}
	}

	@Override
	public void deleteRecord(String id) throws DBException, SQLException {
		OnlCgformHead var2 = (OnlCgformHead) this.getById(id);
		if (var2 == null) {
			throw new DBException("实体配置不存在");
		} else {
			this.baseMapper.deleteById(id);
			this.deleteRelation(var2);
		}
	}

	private void deleteRelation(OnlCgformHead var1) {
		if (var1.getTableType() == 3) {
			LambdaQueryWrapper var2 = Wrappers.lambdaQuery(OnlCgformField.class).eq(OnlCgformField::getCgformHeadId, var1.getId());
			List var3 = this.fieldService.list(var2);
			String var4 = null;
			Iterator var5 = var3.iterator();
			if (var5.hasNext()) {
				OnlCgformField var6 = (OnlCgformField) var5.next();
				var4 = var6.getMainTable();
			}

			if (oConvertUtils.isNotEmpty(var4)) {
				OnlCgformHead var8 = this.baseMapper.selectOne(Wrappers.lambdaQuery(OnlCgformHead.class).eq(OnlCgformHead::getTableName, var4));
				if (var8 != null) {
					String var9 = var8.getSubTableStr();
					if (oConvertUtils.isNotEmpty(var9)) {
						List var7 = (List) Arrays.asList(var9.split(",")).stream().collect(Collectors.toList());
						var7.remove(var1.getTableName());
						var8.setSubTableStr(String.join(",", var7));
						this.baseMapper.updateById(var8);
					}
				}
			}
		}

	}

	@Override
	public List<Map<String, Object>> queryListData(String sql) {
		return this.baseMapper.queryList(sql);
	}

	@Override
	public void saveEnhance(OnlCgformEnhanceJs onlCgformEnhanceJs) {
		this.onlCgformEnhanceJsMapper.insert(onlCgformEnhanceJs);
	}

	@Override
	public OnlCgformEnhanceJs queryEnhance(String code, String type) {
		return (OnlCgformEnhanceJs) this.onlCgformEnhanceJsMapper.selectOne(Wrappers.lambdaQuery(OnlCgformEnhanceJs.class).eq(OnlCgformEnhanceJs::getCgJsType, type).eq(OnlCgformEnhanceJs::getCgformHeadId, code));
	}

	@Override
	public void editEnhance(OnlCgformEnhanceJs onlCgformEnhanceJs) {
		this.onlCgformEnhanceJsMapper.updateById(onlCgformEnhanceJs);
	}

	@Override
	public OnlCgformEnhanceSql queryEnhanceSql(String formId, String buttonCode) {
		return (OnlCgformEnhanceSql) this.onlCgformEnhanceSqlMapper.selectOne(Wrappers.lambdaQuery(OnlCgformEnhanceSql.class).eq(OnlCgformEnhanceSql::getCgformHeadId, formId).eq(OnlCgformEnhanceSql::getButtonCode, buttonCode));
	}

	@Override
	public void saveEnhance(OnlCgformEnhanceSql onlCgformEnhanceSql) {
		this.onlCgformEnhanceSqlMapper.insert(onlCgformEnhanceSql);
	}

	@Override
	public void editEnhance(OnlCgformEnhanceSql onlCgformEnhanceSql) {
		this.onlCgformEnhanceSqlMapper.updateById(onlCgformEnhanceSql);
	}

	@Override
	public OnlCgformEnhanceJava queryEnhanceJava(OnlCgformEnhanceJava onlCgformEnhanceJava) {
		LambdaQueryWrapper<OnlCgformEnhanceJava> var2 = new LambdaQueryWrapper();
		var2.eq(OnlCgformEnhanceJava::getButtonCode, onlCgformEnhanceJava.getButtonCode());
		var2.eq(OnlCgformEnhanceJava::getCgformHeadId, onlCgformEnhanceJava.getCgformHeadId());
		var2.eq(OnlCgformEnhanceJava::getCgJavaType, onlCgformEnhanceJava.getCgJavaType());
		var2.eq(OnlCgformEnhanceJava::getEvent, onlCgformEnhanceJava.getEvent());
		return (OnlCgformEnhanceJava) this.onlCgformEnhanceJavaMapper.selectOne(var2);
	}
	@Override
	public void saveEnhance(OnlCgformEnhanceJava onlCgformEnhanceJava) {
		this.onlCgformEnhanceJavaMapper.insert(onlCgformEnhanceJava);
	}
	@Override
	public void editEnhance(OnlCgformEnhanceJava onlCgformEnhanceJava) {
		this.onlCgformEnhanceJavaMapper.updateById(onlCgformEnhanceJava);
	}
	@Override
	public List<OnlCgformButton> queryButtonList(String code, boolean isListButton) {
		LambdaQueryWrapper<OnlCgformButton> var3 = new LambdaQueryWrapper();
		var3.eq(OnlCgformButton::getButtonStatus, "1");
		var3.eq(OnlCgformButton::getCgformHeadId, code);
		if (isListButton) {
			var3.in(OnlCgformButton::getButtonStyle, new Object[]{"link", "button"});
		} else {
			var3.eq(OnlCgformButton::getButtonStyle, "form");
		}

		var3.orderByAsc(OnlCgformButton::getOrderNum);
		return this.onlCgformButtonMapper.selectList(var3);
	}

	@Override
	public List<OnlCgformButton> queryButtonList(String code) {
		LambdaQueryWrapper<OnlCgformButton> var2 = new LambdaQueryWrapper();
		var2.eq(OnlCgformButton::getButtonStatus, "1");
		var2.eq(OnlCgformButton::getCgformHeadId, code);
		var2.orderByAsc(OnlCgformButton::getOrderNum);
		return this.onlCgformButtonMapper.selectList(var2);
	}

	@Override
	public boolean checkOnlyEnhance(OnlCgformEnhanceJava onlCgformEnhanceJava) {
		LambdaQueryWrapper<OnlCgformEnhanceJava> var2 = new LambdaQueryWrapper();
		var2.eq(OnlCgformEnhanceJava::getButtonCode, onlCgformEnhanceJava.getButtonCode());
		var2.eq(OnlCgformEnhanceJava::getCgformHeadId, onlCgformEnhanceJava.getCgformHeadId());
		Integer var3 = this.onlCgformEnhanceJavaMapper.selectCount(var2);
		if (var3 != null) {
			if (var3 == 1 && oConvertUtils.isEmpty(onlCgformEnhanceJava.getId())) {
				return false;
			}

			if (var3 == 2) {
				return false;
			}
		}

		return true;
	}

	public List<String> queryOnlinetables() {
		return this.baseMapper.queryOnlinetables();
	}

	@Transactional(
			rollbackFor = {Exception.class}
	)
	public void saveDbTable2Online(SysDataSource sysDataSource, String tbname) {
		OnlCgformHead var2 = new OnlCgformHead();
		var2.setTableType(1);
		var2.setIsCheckbox("Y");
		var2.setIsDbSynch("Y");
		var2.setIsTree("N");
		var2.setIsPage("Y");
		var2.setQueryMode("group");
		var2.setTableName(tbname.toLowerCase());
		var2.setTableTxt(tbname);
		var2.setTableVersion(1);
		var2.setFormTemplate("1");
		var2.setCopyType(0);
		var2.setScroll(1);
		var2.setThemeTemplate("normal");
		String var3 = UUIDGenerator.generate();
		var2.setId(var3);
		ArrayList var4 = new ArrayList();

		try {
			List list = DbReadTableUtil.getVolumnVoList(sysDataSource.getDbType(),sysDataSource.getDbUrl(),sysDataSource.getDbUsername(),sysDataSource.getDbPassword(),sysDataSource.getDbName(),tbname);

			for (int var6 = 0; var6 < list.size(); ++var6) {
				ColumnVo var7 = (ColumnVo) list.get(var6);
				LOGGER.info("  columnt : " + var7.toString());
				String var8 = var7.getFieldDbName();
				OnlCgformField cgformField = new OnlCgformField();
				cgformField.setCgformHeadId(var3);
				cgformField.setDbFieldNameOld(var7.getFieldDbName().toLowerCase());
				cgformField.setDbFieldName(var7.getFieldDbName().toLowerCase());
				if (oConvertUtils.isNotEmpty(var7.getFiledComment())) {
					cgformField.setDbFieldTxt(var7.getFiledComment());
				} else {
					cgformField.setDbFieldTxt(var7.getFieldName());
				}

				cgformField.setDbIsKey(0);
				cgformField.setIsShowForm(1);
				cgformField.setIsQuery(0);
				cgformField.setFieldMustInput("0");
				cgformField.setIsShowList(1);
				cgformField.setOrderNum(var6 + 1);
				cgformField.setQueryMode("single");
				cgformField.setDbLength(oConvertUtils.getInt(var7.getPrecision()));
				cgformField.setFieldLength(120);
				cgformField.setDbPointLength(oConvertUtils.getInt(var7.getScale()));
				cgformField.setFieldShowType("text");
				cgformField.setDbIsNull("Y".equals(var7.getNullable()) ? 1 : 0);
				cgformField.setIsReadOnly(0);
				if ("id".equalsIgnoreCase(var8)) {
					String[] var10 = new String[]{"java.lang.Integer", "java.lang.Long"};
					String var11 = var7.getFieldType();
					if (Arrays.asList(var10).contains(var11)) {
						var2.setIdType("NATIVE");
					} else {
						var2.setIdType("UUID");
					}

					cgformField.setDbIsKey(1);
					cgformField.setIsShowForm(0);
					cgformField.setIsShowList(0);
					cgformField.setIsReadOnly(1);
				}

				if ("java.lang.Integer".equalsIgnoreCase(var7.getFieldType())) {
					cgformField.setDbType("int");
				} else if ("java.lang.Long".equalsIgnoreCase(var7.getFieldType())) {
					cgformField.setDbType("int");
				} else if ("java.util.Date".equalsIgnoreCase(var7.getFieldType())) {
					cgformField.setDbType("Date");
					cgformField.setFieldShowType("date");
				} else if (!"java.lang.Double".equalsIgnoreCase(var7.getFieldType()) && !"java.lang.Float".equalsIgnoreCase(var7.getFieldType())) {
					if (!"java.math.BigDecimal".equalsIgnoreCase(var7.getFieldType()) && !"BigDecimal".equalsIgnoreCase(var7.getFieldType())) {
						if (!"byte[]".equalsIgnoreCase(var7.getFieldType()) && !var7.getFieldType().contains("blob")) {
							if (!"java.lang.Object".equals(var7.getFieldType()) || !"text".equalsIgnoreCase(var7.getFieldDbType()) && !"ntext".equalsIgnoreCase(var7.getFieldDbType())) {
								if ("java.lang.Object".equals(var7.getFieldType()) && "image".equalsIgnoreCase(var7.getFieldDbType())) {
									cgformField.setDbType("Blob");
								} else {
									cgformField.setDbType("string");
								}
							} else {
								cgformField.setDbType("Text");
								cgformField.setFieldShowType("textarea");
							}
						} else {
							cgformField.setDbType("Blob");
							var7.setCharmaxLength((String) null);
						}
					} else {
						cgformField.setDbType("BigDecimal");
					}
				} else {
					cgformField.setDbType("double");
				}

				if (oConvertUtils.isEmpty(var7.getPrecision()) && oConvertUtils.isNotEmpty(var7.getCharmaxLength())) {
					if (Long.valueOf(var7.getCharmaxLength()) >= 3000L) {
						cgformField.setDbType("Text");
						cgformField.setFieldShowType("textarea");

						try {
							cgformField.setDbLength(Integer.valueOf(var7.getCharmaxLength()));
						} catch (Exception var12) {
							LOGGER.error(var12.getMessage(), var12);
						}
					} else {
						cgformField.setDbLength(Integer.valueOf(var7.getCharmaxLength()));
					}
				} else {
					if (oConvertUtils.isNotEmpty(var7.getPrecision())) {
						cgformField.setDbLength(Integer.valueOf(var7.getPrecision()));
					} else if (cgformField.getDbType().equals("int")) {
						cgformField.setDbLength(10);
					}

					if (oConvertUtils.isNotEmpty(var7.getScale())) {
						cgformField.setDbPointLength(Integer.valueOf(var7.getScale()));
					}
				}

				if (oConvertUtils.getInt(var7.getPrecision()) == -1 && oConvertUtils.getInt(var7.getScale()) == 0) {
					cgformField.setDbType("Text");
				}

				if ("Blob".equals(cgformField.getDbType()) || "Text".equals(cgformField.getDbType()) || "Date".equals(cgformField.getDbType())) {
					cgformField.setDbLength(0);
					cgformField.setDbPointLength(0);
				}

				var4.add(cgformField);
			}
		} catch (Exception var13) {
			LOGGER.error(var13.getMessage(), var13);
		}

		if (oConvertUtils.isEmpty(var2.getFormCategory())) {
			var2.setFormCategory("bdfl_include");
		}

		this.save(var2);
		this.fieldService.saveBatch(var4);
	}

	private void saveRelation(OnlCgformHead cgformHead, List<OnlCgformField> cgformFieldList) {
		//子表设置
		if (cgformHead.getTableType() == 3) {
			cgformHead = this.baseMapper.selectById(cgformHead.getId());
			for (int var3 = 0; var3 < cgformFieldList.size(); ++var3) {
				OnlCgformField var4 = (OnlCgformField) cgformFieldList.get(var3);
				String var5 = var4.getMainTable();
				//主表名称不为空
				if (!oConvertUtils.isEmpty(var5)) {
					OnlCgformHead var6 = this.baseMapper.selectOne(Wrappers.lambdaQuery(OnlCgformHead.class).eq(OnlCgformHead::getTableName, var5));
					if (var6 != null) {
						String var7 = var6.getSubTableStr();
						if (oConvertUtils.isEmpty(var7)) {
							var7 = cgformHead.getTableName();
						} else if (var7.indexOf(cgformHead.getTableName()) < 0) {
							ArrayList var8 = new ArrayList(Arrays.asList(var7.split(",")));

							for (int var9 = 0; var9 < var8.size(); ++var9) {
								String var10 = (String) var8.get(var9);
								OnlCgformHead var11 = this.baseMapper.selectOne(Wrappers.lambdaQuery(OnlCgformHead.class).eq(OnlCgformHead::getTableName, var10));
								if (var11 != null && cgformHead.getTabOrderNum() < oConvertUtils.getInt(var11.getTabOrderNum(), 0)) {
									var8.add(var9, cgformHead.getTableName());
									break;
								}
							}

							if (var8.indexOf(cgformHead.getTableName()) < 0) {
								var8.add(cgformHead.getTableName());
							}

							var7 = String.join(",", var8);
						}

						var6.setSubTableStr(var7);
						this.baseMapper.updateById(var6);
						break;
					}
				}
			}
		} else {
			List var12 = this.baseMapper.selectList(Wrappers.lambdaQuery(OnlCgformHead.class).like(OnlCgformHead::getSubTableStr, cgformHead.getTableName()));
			if (var12 != null && var12.size() > 0) {
				Iterator var13 = var12.iterator();

				while (var13.hasNext()) {
					OnlCgformHead var14 = (OnlCgformHead) var13.next();
					String var15 = var14.getSubTableStr();
					if (var14.getSubTableStr().equals(cgformHead.getTableName())) {
						var15 = "";
					} else if (var14.getSubTableStr().startsWith(cgformHead.getTableName() + ",")) {
						var15 = var15.replace(cgformHead.getTableName() + ",", "");
					} else if (var14.getSubTableStr().endsWith("," + cgformHead.getTableName())) {
						var15 = var15.replace("," + cgformHead.getTableName(), "");
					} else if (var14.getSubTableStr().indexOf("," + cgformHead.getTableName() + ",") != -1) {
						var15 = var15.replace("," + cgformHead.getTableName() + ",", ",");
					}

					var14.setSubTableStr(var15);
					this.baseMapper.updateById(var14);
				}
			}
		}

	}

	@Transactional(
			rollbackFor = {Exception.class}
	)
	@Override
	public String saveManyFormData(String code, JSONObject json, String xAccessToken) throws DBException, BusinessException {
		OnlCgformHead onlCgformHead = (OnlCgformHead) this.getById(code);
		if (onlCgformHead == null) {
			throw new DBException("数据库主表ID[" + code + "]不存在");
		} else {
			String var5 = "add";
			this.executeEnhanceJava(var5, "start", onlCgformHead, json);
			String var6 = CgformSqlUtil.parsePattern(onlCgformHead.getTableName());
			if (onlCgformHead.getTableType() == 2) {
				String var7 = onlCgformHead.getSubTableStr();
				if (oConvertUtils.isNotEmpty(var7)) {
					String[] var8 = var7.split(",");
					String[] var9 = var8;
					int var10 = var8.length;

					for (int var11 = 0; var11 < var10; ++var11) {
						String var12 = var9[var11];
						JSONArray var13 = json.getJSONArray(var12);
						if (var13 != null && var13.size() != 0) {
							OnlCgformHead var14 = this.baseMapper.selectOne(Wrappers.lambdaQuery(OnlCgformHead.class).eq(OnlCgformHead::getTableName, var12));
							if (var14 != null) {
								List var15 = this.fieldService.list(Wrappers.lambdaQuery(OnlCgformField.class).eq(OnlCgformField::getCgformHeadId, var14.getId()));
								String var16 = "";
								String var17 = null;
								Iterator var18 = var15.iterator();

								while (var18.hasNext()) {
									OnlCgformField var19 = (OnlCgformField) var18.next();
									if (!oConvertUtils.isEmpty(var19.getMainField())) {
										var16 = var19.getDbFieldName();
										String var20 = var19.getMainField();
										if (json.get(var20.toLowerCase()) != null) {
											var17 = json.getString(var20.toLowerCase());
										}

										if (json.get(var20.toUpperCase()) != null) {
											var17 = json.getString(var20.toUpperCase());
										}
									}
								}

								for (int var27 = 0; var27 < var13.size(); ++var27) {
									JSONObject var28 = var13.getJSONObject(var27);
									if (var17 != null) {
										var28.put(var16, var17);
									}

									this.fieldService.saveFormData(var15, var12, var28);
								}
							}
						}
					}
				}
			}

			if ("Y".equals(onlCgformHead.getIsTree())) {
				this.fieldService.saveTreeFormData(code, var6, json, onlCgformHead.getTreeIdField(), onlCgformHead.getTreeParentIdField());
			} else {
				this.fieldService.saveFormData(code, var6, json, false);
			}

			this.executeEnhanceSql(var5, code, json);
			this.executeEnhanceJava(var5, "end", onlCgformHead, json);
			if (oConvertUtils.isNotEmpty(json.get("bpm_status")) || oConvertUtils.isNotEmpty(json.get("bpm_status".toUpperCase()))) {
				try {
					HttpHeaders var22 = new HttpHeaders();
					var22.setContentType(MediaType.parseMediaType("application/json;charset=UTF-8"));
					var22.set("Accept", "application/json;charset=UTF-8");
					//代码扫描
					xAccessToken = xAccessToken.replaceAll("(\r\n|\r|\n|\n\r)","");
					var22.set("X-Access-Token", xAccessToken);
					JSONObject var23 = new JSONObject();
					var23.put("flowCode", "onl_" + onlCgformHead.getTableName());
					var23.put("id", json.get("id"));
					var23.put("formUrl", "modules/bpm/task/form/OnlineFormDetail");
					var23.put("formUrlMobile", "online/OnlineDetailForm");
					String var24 = RestUtil.getBaseUrl() + "/process/extActProcess/saveMutilProcessDraft";
					JSONObject var25 = (JSONObject) RestUtil.request(var24, HttpMethod.POST, var22, (JSONObject) null, var23, JSONObject.class).getBody();
					if (var25 != null) {
						String var26 = var25.getString("result");
						LOGGER.info("保存流程草稿 dataId : " + var26);
					}
				} catch (Exception var21) {
					LOGGER.error("保存流程草稿异常, " + var21.getMessage(), var21);
				}
			}

			return onlCgformHead.getTableName();
		}
	}
	@Override
	public Map<String, Object> querySubFormData(String table, String mainId) throws DBException {
		new HashMap();
		OnlCgformHead var4 = (OnlCgformHead) this.getOne(Wrappers.lambdaQuery(OnlCgformHead.class).eq(OnlCgformHead::getTableName, table));
		if (var4 == null) {
			throw new DBException("数据库子表[" + table + "]不存在");
		} else {
			List var5 = this.fieldService.queryFormFields(var4.getId(), false);
			String var6 = null;
			Iterator var7 = var5.iterator();

			while (var7.hasNext()) {
				OnlCgformField var8 = (OnlCgformField) var7.next();
				if (oConvertUtils.isNotEmpty(var8.getMainField())) {
					var6 = var8.getDbFieldName();
					break;
				}
			}

			List var9 = this.fieldService.querySubFormData(var5, table, var6, mainId);
			Map var3 = null;
			if (var9 != null){
				if(var9.size() == 0){
					throw new DBException("数据库子表[" + table + "]未找到相关信息,主表ID为" + mainId);
				}else if(var9.size() > 1){
					throw new DBException("数据库子表[" + table + "]存在多条记录,主表ID为" + mainId);
				}else{
					var3 = (Map) var9.get(0);
				}

			}
			return var3;
		}
	}
	@Override
	public List<Map<String, Object>> queryManySubFormData(String table, String mainId) throws DBException {
		OnlCgformHead var3 = (OnlCgformHead) this.getOne(Wrappers.lambdaQuery(OnlCgformHead.class).eq(OnlCgformHead::getTableName, table));
		if (var3 == null) {
			throw new DBException("数据库子表[" + table + "]不存在");
		} else {
			List var4 = this.fieldService.queryFormFields(var3.getId(), false);
			String var5 = null;
			String var6 = null;
			String var7 = null;
			Iterator var8 = var4.iterator();

			OnlCgformField var9;
			while (var8.hasNext()) {
				var9 = (OnlCgformField) var8.next();
				if (oConvertUtils.isNotEmpty(var9.getMainField())) {
					var5 = var9.getDbFieldName();
					var6 = var9.getMainTable();
					var7 = var9.getMainField();
					break;
				}
			}

			ArrayList var16 = new ArrayList();
			var9 = new OnlCgformField();
			var9.setDbFieldName(var7);
			var16.add(var9);
			Map var10 = this.fieldService.queryFormData((List) var16, var6, mainId);
			String var11 = var10.get(var7).toString();
			List var12 = this.fieldService.querySubFormData(var4, table, var5, var11);
			ArrayList var13 = null;
			if (var12 != null) {
				if(var12.size() == 0){
					throw new DBException("数据库子表[" + table + "]未找到相关信息,主表ID为" + mainId);
				}else{
					var13 = new ArrayList(var12.size());
					Iterator var14 = var12.iterator();
					while (var14.hasNext()) {
						Map var15 = (Map) var14.next();
						var13.add(CgformSqlUtil.query(var15));
					}
				}
			}
			return var13 == null ? new ArrayList<>() : var13;
		}
	}
	@Override
	public Map<String, Object> queryManyFormData(String code, String id) throws DBException {
		OnlCgformHead var3 = (OnlCgformHead) this.getById(code);
		if (var3 == null) {
			throw new DBException("数据库主表ID[" + code + "]不存在");
		} else {
			List var4 = this.fieldService.queryFormFields(code, true);
			Map var5 = this.fieldService.queryFormData(var4, var3.getTableName(), id);
			if (var3.getTableType() == 2) {
				String var6 = var3.getSubTableStr();
				if (oConvertUtils.isNotEmpty(var6)) {
					String[] var7 = var6.split(",");
					String[] var8 = var7;
					int var9 = var7.length;

					for (int var10 = 0; var10 < var9; ++var10) {
						String var11 = var8[var10];
						OnlCgformHead var12 = this.baseMapper.selectOne(Wrappers.lambdaQuery(OnlCgformHead.class).eq(OnlCgformHead::getTableName, var11));
						if (var12 != null) {
							List var13 = this.fieldService.queryFormFields(var12.getId(), false);
							String var14 = "";
							String var15 = null;
							Iterator var16 = var13.iterator();

							while (var16.hasNext()) {
								OnlCgformField var17 = (OnlCgformField) var16.next();
								if (!oConvertUtils.isEmpty(var17.getMainField())) {
									var14 = var17.getDbFieldName();
									String var18 = var17.getMainField();
									if (null == var5.get(var18)) {
										var15 = var5.get(var18.toUpperCase()).toString();
									} else {
										var15 = var5.get(var18).toString();
									}
								}
							}

							List var19 = this.fieldService.querySubFormData(var13, var11, var14, var15);
							if (var19 != null && var19.size() != 0) {
								var5.put(var11, CgformSqlUtil.parseData(var19));
							} else {
								var5.put(var11, new String[0]);
							}
						}
					}
				}
			}

			return var5;
		}
	}

	@Transactional(
			rollbackFor = {Exception.class}
	)
	@Override
	public String editManyFormData(String code, JSONObject json) throws DBException, BusinessException {
		OnlCgformHead var3 = (OnlCgformHead) this.getById(code);
		if (var3 == null) {
			throw new DBException("数据库主表ID[" + code + "]不存在");
		} else {
			String var4 = "edit";
			this.executeEnhanceJava(var4, "start", var3, json);
			String var5 = var3.getTableName();
			if ("Y".equals(var3.getIsTree())) {
				this.fieldService.editTreeFormData(code, var5, json, var3.getTreeIdField(), var3.getTreeParentIdField());
			} else {
				this.fieldService.editFormData(code, var5, json, false);
			}

			if (var3.getTableType() == 2) {
				String var6 = var3.getSubTableStr();
				if (oConvertUtils.isNotEmpty(var6)) {
					String[] var7 = var6.split(",");
					String[] var8 = var7;
					int var9 = var7.length;

					for (int var10 = 0; var10 < var9; ++var10) {
						String var11 = var8[var10];
						OnlCgformHead var12 = this.baseMapper.selectOne(Wrappers.lambdaQuery(OnlCgformHead.class).eq(OnlCgformHead::getTableName, var11));
						if (var12 != null) {
							List var13 = this.fieldService.list(Wrappers.lambdaQuery(OnlCgformField.class).eq(OnlCgformField::getCgformHeadId, var12.getId()));
							String var14 = "";
							String var15 = null;
							Iterator var16 = var13.iterator();

							while (var16.hasNext()) {
								OnlCgformField var17 = (OnlCgformField) var16.next();
								if (!oConvertUtils.isEmpty(var17.getMainField())) {
									var14 = var17.getDbFieldName();
									String var18 = var17.getMainField();
									if (json.get(var18.toLowerCase()) != null) {
										var15 = json.getString(var18.toLowerCase());
									}

									if (json.get(var18.toUpperCase()) != null) {
										var15 = json.getString(var18.toUpperCase());
									}
								}
							}

							if (!oConvertUtils.isEmpty(var15)) {
								this.fieldService.deleteAutoList(var11, var14, var15);
								JSONArray var19 = json.getJSONArray(var11);
								if (var19 != null && var19.size() != 0) {
									for (int var20 = 0; var20 < var19.size(); ++var20) {
										JSONObject var21 = var19.getJSONObject(var20);
										if (var15 != null) {
											var21.put(var14, var15);
										}

										this.fieldService.saveFormData(var13, var11, var21);
									}
								}
							}
						}
					}
				}
			}

			this.executeEnhanceJava(var4, "end", var3, json);
			this.executeEnhanceSql(var4, code, json);
			return var5;
		}
	}
	@Override
	public int executeEnhanceJava(String buttonCode, String eventType, OnlCgformHead head, JSONObject json) throws BusinessException {
		LambdaQueryWrapper<OnlCgformEnhanceJava> var5 = new LambdaQueryWrapper();
		var5.eq(OnlCgformEnhanceJava::getActiveStatus, "1");
		var5.eq(OnlCgformEnhanceJava::getButtonCode, buttonCode);
		var5.eq(OnlCgformEnhanceJava::getCgformHeadId, head.getId());
		var5.eq(OnlCgformEnhanceJava::getEvent, eventType);
		OnlCgformEnhanceJava var6 = (OnlCgformEnhanceJava) this.onlCgformEnhanceJavaMapper.selectOne(var5);
		Object var7 = this.a(var6);
		if (var7 != null && var7 instanceof CgformEnhanceJavaInter) {
			CgformEnhanceJavaInter var8 = (CgformEnhanceJavaInter) var7;
			return var8.execute(head.getTableName(), json);
		} else {
			return 1;
		}
	}
	@Override
	public void executeEnhanceExport(OnlCgformHead head, List<Map<String, Object>> dataList) throws BusinessException {
		this.executeEnhanceList(head, "export", dataList);
	}
	@Override
	public void executeEnhanceList(OnlCgformHead head, String buttonCode, List<Map<String, Object>> dataList) throws BusinessException {
		LambdaQueryWrapper<OnlCgformEnhanceJava> var4 = new LambdaQueryWrapper();
		var4.eq(OnlCgformEnhanceJava::getActiveStatus, "1");
		var4.eq(OnlCgformEnhanceJava::getButtonCode, buttonCode);
		var4.eq(OnlCgformEnhanceJava::getCgformHeadId, head.getId());
		List var5 = this.onlCgformEnhanceJavaMapper.selectList(var4);
		if (var5 != null && var5.size() > 0) {
			Object var6 = this.a((OnlCgformEnhanceJava) var5.get(0));
			if (var6 != null && var6 instanceof CgformEnhanceJavaListInter) {
				CgformEnhanceJavaListInter var7 = (CgformEnhanceJavaListInter) var6;
				var7.execute(head.getTableName(), dataList);
			}
		}

	}

	private Object a(OnlCgformEnhanceJava var1) {
		if (var1 != null) {
			String var2 = var1.getCgJavaType();
			String var3 = var1.getCgJavaValue();
			if (oConvertUtils.isNotEmpty(var3)) {
				Object var4 = null;
				if ("class".equals(var2)) {
					try {
						var4 = MyClassLoader.getClassByScn(var3).newInstance();
					} catch (InstantiationException var6) {
						LOGGER.error(var6.getMessage(), var6);
					} catch (IllegalAccessException var7) {
						LOGGER.error(var7.getMessage(), var7);
					}
				} else if ("spring".equals(var2)) {
					var4 = SpringContextUtils.getBean(var3);
				}

				return var4;
			}
		}

		return null;
	}
	@Override
	public void executeEnhanceSql(String buttonCode, String formId, JSONObject json) {
		LambdaQueryWrapper<OnlCgformEnhanceSql> var4 = new LambdaQueryWrapper();
		var4.eq(OnlCgformEnhanceSql::getButtonCode, buttonCode);
		var4.eq(OnlCgformEnhanceSql::getCgformHeadId, formId);
		OnlCgformEnhanceSql var5 = (OnlCgformEnhanceSql) this.onlCgformEnhanceSqlMapper.selectOne(var4);
		if (var5 != null && oConvertUtils.isNotEmpty(var5.getCgbSql())) {
			String var6 = CgformSqlUtil.parseSql(var5.getCgbSql(), json);
			String[] var7 = var6.split(";");
			String[] var8 = var7;
			int var9 = var7.length;

			for (int var10 = 0; var10 < var9; ++var10) {
				String var11 = var8[var10];
				if (var11 != null && !var11.toLowerCase().trim().equals("")) {
					LOGGER.info(" online sql 增强： " + var11);
					//this.baseMapper.executeDDL(var11);
					jdbcTemplate.update(var11);
				}
			}
		}

	}
	@Override
	public void executeCustomerButton(String buttonCode, String formId, String dataId) throws BusinessException {
		OnlCgformHead var4 = (OnlCgformHead) this.getById(formId);
		if (var4 == null) {
			throw new BusinessException("未找到表配置信息");
		} else {
			Map var5 = this.baseMapper.queryOneByTableNameAndId(CgformSqlUtil.parsePattern(var4.getTableName()), dataId);
			JSONObject var6 = JSONObject.parseObject(JSON.toJSONString(var5));
			this.executeEnhanceJava(buttonCode, "start", var4, var6);
			this.executeEnhanceSql(buttonCode, formId, var6);
			this.executeEnhanceJava(buttonCode, "end", var4, var6);
		}
	}
	@Override
	public List<OnlCgformButton> queryValidButtonList(String headId) {
		LambdaQueryWrapper<OnlCgformButton> var2 = new LambdaQueryWrapper();
		var2.eq(OnlCgformButton::getCgformHeadId, headId);
		var2.eq(OnlCgformButton::getButtonStatus, "1");
		var2.orderByAsc(OnlCgformButton::getOrderNum);
		return this.onlCgformButtonMapper.selectList(var2);
	}
	@Override
	public OnlCgformEnhanceJs queryEnhanceJs(String formId, String cgJsType) {
		LambdaQueryWrapper<OnlCgformEnhanceJs> var3 = new LambdaQueryWrapper();
		var3.eq(OnlCgformEnhanceJs::getCgformHeadId, formId);
		var3.eq(OnlCgformEnhanceJs::getCgJsType, cgJsType);
		return (OnlCgformEnhanceJs) this.onlCgformEnhanceJsMapper.selectOne(var3);
	}

	@Transactional(
			rollbackFor = {Exception.class}
	)
	@Override
	public void deleteOneTableInfo(String formId, String dataId) throws BusinessException {
		OnlCgformHead var3 = (OnlCgformHead) this.getById(formId);
		if (var3 == null) {
			throw new BusinessException("未找到表配置信息");
		} else {
			String var4 = CgformSqlUtil.parsePattern(var3.getTableName());
			Map var5 = this.baseMapper.queryOneByTableNameAndId(var4, dataId);
			if (var5 == null) {
				throw new BusinessException("未找到数据信息");
			} else {
				String var6 = "delete";
				JSONObject var7 = JSONObject.parseObject(JSON.toJSONString(var5));
				this.executeEnhanceJava(var6, "start", var3, var7);
				this.updateParentNode(var3, dataId);
				if (var3.getTableType() == 2) {
					this.fieldService.deleteAutoListMainAndSub(var3, dataId);
				} else {
					String var8 = "delete from " + var4 + " where id = '" + dataId + "'";
					this.baseMapper.deleteOne(var8);
				}

				this.executeEnhanceSql(var6, formId, var7);
				this.executeEnhanceJava(var6, "end", var3, var7);
			}
		}
	}
	@Override
	public JSONObject queryFormItem(OnlCgformHead head) {
		List var2 = this.fieldService.queryAvailableFields(head.getId(), head.getTableName(), head.getTaskId(), false);
		ArrayList var3 = new ArrayList();
		List var4;
		if (oConvertUtils.isEmpty(head.getTaskId())) {
			var4 = this.fieldService.queryDisabledFields(head.getTableName());
			if (var4 != null && var4.size() > 0 && var4.get(0) != null) {
				var3.addAll(var4);
			}
		} else {
			var4 = this.fieldService.queryDisabledFields(head.getTableName(), head.getTaskId());
			if (var4 != null && var4.size() > 0 && var4.get(0) != null) {
				var3.addAll(var4);
			}
		}

		JSONObject var14 = CgformSqlUtil.a((List) var2, (List) var3, (OnlFieldModel) null);
		if (head.getTableType() == 2) {
			String var5 = head.getSubTableStr();
			if (oConvertUtils.isNotEmpty(var5)) {
				String[] var6 = var5.split(",");
				int var7 = var6.length;

				for (int var8 = 0; var8 < var7; ++var8) {
					String var9 = var6[var8];
					OnlCgformHead var10 = this.baseMapper.selectOne(Wrappers.lambdaQuery(OnlCgformHead.class).eq(OnlCgformHead::getTableName, var9));
					if (var10 != null) {
						List var11 = this.fieldService.queryAvailableFields(var10.getId(), var10.getTableName(), (String) null, false);
						List var12 = this.fieldService.queryDisabledFields(var10.getTableName());
						JSONObject var13 = new JSONObject();
						if (1 == var10.getRelationType()) {
							var13 = CgformSqlUtil.a((List) var11, (List) var12, (OnlFieldModel) null);
						} else {
							var13.put("columns", CgformSqlUtil.parseViewConfig(var11, var12));
						}

						var13.put("relationType", var10.getRelationType());
						var13.put("view", "tab");
						var13.put("order", var10.getTabOrderNum());
						var13.put("formTemplate", var10.getFormTemplate());
						var13.put("describe", var10.getTableTxt());
						var13.put("key", var10.getTableName());
						var14.getJSONObject("properties").put(var10.getTableName(), var13);
					}
				}
			}
		}

		return var14;
	}
	@Override
	public List<String> generateCode(OnlGenerateModel model) throws Exception {
		TableVo var2 = new TableVo();
		var2.setEntityName(model.getEntityName());
		var2.setEntityPackage(model.getEntityPackage());
		var2.setFtlDescription(model.getFtlDescription());
		var2.setTableName(model.getTableName());
		var2.setSearchFieldNum(-1);
		ArrayList var3 = new ArrayList();
		ArrayList var4 = new ArrayList();
		this.a(model.getCode(), var3, var4);
		OnlCgformHead var5 = this.baseMapper.selectOne(Wrappers.lambdaQuery(OnlCgformHead.class).eq(OnlCgformHead::getId, model.getCode()));
		HashMap var6 = new HashMap();
		var6.put("scroll", var5.getScroll() == null ? "0" : var5.getScroll().toString());
		String var7 = var5.getFormTemplate();
		if (oConvertUtils.isEmpty(var7)) {
			var2.setFieldRowNum(1);
		} else {
			var2.setFieldRowNum(Integer.parseInt(var7));
		}

		if ("Y".equals(var5.getIsTree())) {
			var6.put("pidField", var5.getTreeParentIdField());
			var6.put("hasChildren", var5.getTreeIdField());
			var6.put("textField", var5.getTreeFieldname());
		}

		var2.setExtendParams(var6);
		CgformEnum var8 = CgformEnum.getCgformEnumByConfig(model.getJspMode());
		List var9 = (new CodeGenerateOne(var2, var3, var4)).generateCodeFile(model.getProjectPath(), var8.getTemplatePath(), var8.getStylePath());
		return var9;
	}
	@Override
	public List<String> generateOneToMany(OnlGenerateModel model) throws Exception {
		MainTableVo var2 = new MainTableVo();
		var2.setEntityName(model.getEntityName());
		var2.setEntityPackage(model.getEntityPackage());
		var2.setFtlDescription(model.getFtlDescription());
		var2.setTableName(model.getTableName());
		OnlCgformHead var3 = this.baseMapper.selectOne(Wrappers.lambdaQuery(OnlCgformHead.class).eq(OnlCgformHead::getId, model.getCode()));
		String var4 = var3.getFormTemplate();
		if (oConvertUtils.isEmpty(var4)) {
			var2.setFieldRowNum(1);
		} else {
			var2.setFieldRowNum(Integer.parseInt(var4));
		}

		ArrayList var5 = new ArrayList();
		ArrayList var6 = new ArrayList();
		this.a(model.getCode(), var5, var6);
		List var7 = model.getSubList();
		ArrayList var8 = new ArrayList();
		Iterator var9 = var7.iterator();

		while (var9.hasNext()) {
			OnlGenerateModel var10 = (OnlGenerateModel) var9.next();
			OnlCgformHead var11 = this.baseMapper.selectOne(Wrappers.lambdaQuery(OnlCgformHead.class).eq(OnlCgformHead::getTableName, var10.getTableName()));
			if (var11 != null) {
				SubTableVo var12 = new SubTableVo();
				var12.setEntityName(var10.getEntityName());
				var12.setEntityPackage(model.getEntityPackage());
				var12.setTableName(var10.getTableName());
				var12.setFtlDescription(var10.getFtlDescription());
				Integer var13 = var11.getRelationType();
				var12.setForeignRelationType(var13 == 1 ? "1" : "0");
				ArrayList var14 = new ArrayList();
				ArrayList var15 = new ArrayList();
				OnlCgformField var16 = this.a(var11.getId(), var14, var15);
				if (var16 != null) {
					var12.setOriginalForeignKeys(new String[]{var16.getDbFieldName()});
					var12.setForeignKeys(new String[]{var16.getDbFieldName()});
					var12.setColums(var14);
					var12.setOriginalColumns(var15);
					var8.add(var12);
				}
			}
		}

		CgformEnum var17 = CgformEnum.getCgformEnumByConfig(model.getJspMode());
		List var18 = (new CodeGenerateOneToMany(var2, var5, var6, var8)).generateCodeFile(model.getProjectPath(), var17.getTemplatePath(), var17.getStylePath());
		return var18;
	}

	private OnlCgformField a(String var1, List<ColumnVo> var2, List<ColumnVo> var3) {
		LambdaQueryWrapper<OnlCgformField> var4 = new LambdaQueryWrapper();
		var4.eq(OnlCgformField::getCgformHeadId, var1);
		var4.orderByAsc(OnlCgformField::getOrderNum);
		List var5 = this.fieldService.list(var4);
		OnlCgformField var6 = null;

		OnlCgformField var8;
		ColumnVo var9;
		for (Iterator var7 = var5.iterator(); var7.hasNext();
			//var9.setSort("1".equals(var8.getSortFlag()) ? "Y" : "N")
		) {
			var8 = (OnlCgformField) var7.next();
			if (oConvertUtils.isNotEmpty(var8.getMainTable())) {
				var6 = var8;
			}

			var9 = new ColumnVo();
			var9.setFieldLength(var8.getFieldLength());
			var9.setFieldHref(var8.getFieldHref());
			var9.setFieldValidType(var8.getFieldValidType());
			var9.setFieldDefault(var8.getDbDefaultVal());
			var9.setFieldShowType(var8.getFieldShowType());
			var9.setFieldOrderNum(var8.getOrderNum());
			var9.setIsKey(var8.getDbIsKey() == 1 ? "Y" : "N");
			var9.setIsShow(var8.getIsShowForm() == 1 ? "Y" : "N");
			var9.setIsShowList(var8.getIsShowList() == 1 ? "Y" : "N");
			var9.setIsQuery(var8.getIsQuery() == 1 ? "Y" : "N");
			var9.setQueryMode(var8.getQueryMode());
			var9.setDictField(var8.getDictField());
			if (oConvertUtils.isNotEmpty(var8.getDictTable()) && var8.getDictTable().indexOf("where") > 0) {
				var9.setDictTable(var8.getDictTable().split("where")[0].trim());
			} else {
				var9.setDictTable(var8.getDictTable());
			}

			var9.setDictText(var8.getDictText());
			var9.setFieldDbName(var8.getDbFieldName());
			var9.setFieldName(oConvertUtils.camelName(var8.getDbFieldName()));
			var9.setFiledComment(var8.getDbFieldTxt());
			var9.setFieldDbType(var8.getDbType());
			var9.setFieldType(this.a(var8.getDbType()));
			var9.setClassType(var8.getFieldShowType());
			var9.setClassType_row(var8.getFieldShowType());
			if (var8.getDbIsNull() != 0 && !"*".equals(var8.getFieldValidType()) && !"1".equals(var8.getFieldMustInput())) {
				var9.setNullable("Y");
			} else {
				var9.setNullable("N");
			}

			if ("switch".equals(var8.getFieldShowType())) {
				var9.setDictField(var8.getFieldExtendJson());
			}

			var3.add(var9);
			if (var8.getIsShowForm() == 1 || var8.getIsShowList() == 1) {
				var2.add(var9);
			}
		}

		return var6;
	}

	private String a(String var1) {
		var1 = var1.toLowerCase();
		if (var1.indexOf("int") >= 0) {
			return "java.lang.Integer";
		} else if (var1.indexOf("double") >= 0) {
			return "java.lang.Double";
		} else if (var1.indexOf("decimal") >= 0) {
			return "java.math.BigDecimal";
		} else {
			return var1.indexOf("date") >= 0 ? "java.util.Date" : "java.lang.String";
		}
	}
	@Override
	public void addCrazyFormData(String tbname, JSONObject json) throws DBException, UnsupportedEncodingException {
		OnlCgformHead var3 = (OnlCgformHead) this.getOne(Wrappers.lambdaQuery(OnlCgformHead.class).eq(OnlCgformHead::getTableName, tbname));
		if (var3 == null) {
			throw new DBException("数据库主表[" + tbname + "]不存在");
		} else {
			if (var3.getTableType() == 2) {
				String var4 = var3.getSubTableStr();
				if (var4 != null) {
					String[] var5 = var4.split(",");
					String[] var6 = var5;
					int var7 = var5.length;

					for (int var8 = 0; var8 < var7; ++var8) {
						String var9 = var6[var8];
						String var10 = json.getString("sub-table-design_" + var9);
						if (!oConvertUtils.isEmpty(var10)) {
							JSONArray var11 = JSONArray.parseArray(URLDecoder.decode(var10, "UTF-8"));
							if (var11 != null && var11.size() != 0) {
								OnlCgformHead var12 = this.baseMapper.selectOne(Wrappers.lambdaQuery(OnlCgformHead.class).eq(OnlCgformHead::getTableName, var9));
								if (var12 != null) {
									List var13 = this.fieldService.list(Wrappers.lambdaQuery(OnlCgformField.class).eq(OnlCgformField::getCgformHeadId, var12.getId()));
									String var14 = "";
									String var15 = null;
									Iterator var16 = var13.iterator();

									while (var16.hasNext()) {
										OnlCgformField var17 = (OnlCgformField) var16.next();
										if (!oConvertUtils.isEmpty(var17.getMainField())) {
											var14 = var17.getDbFieldName();
											String var18 = var17.getMainField();
											var15 = json.getString(var18);
										}
									}

									for (int var19 = 0; var19 < var11.size(); ++var19) {
										JSONObject var20 = var11.getJSONObject(var19);
										if (var15 != null) {
											var20.put(var14, var15);
										}

										this.fieldService.executeInsertSQL(CgformSqlUtil.parseInsertSql(var9, var13, var20));
									}
								}
							}
						}
					}
				}
			}

			this.fieldService.saveFormData(var3.getId(), tbname, json, true);
		}
	}
	@Override
	public void editCrazyFormData(String tbname, JSONObject json) throws DBException, UnsupportedEncodingException {
		OnlCgformHead var3 = (OnlCgformHead) this.getOne(Wrappers.lambdaQuery(OnlCgformHead.class).eq(OnlCgformHead::getTableName, tbname));
		if (var3 == null) {
			throw new DBException("数据库主表[" + tbname + "]不存在");
		} else {
			if (var3.getTableType() == 2) {
				String var4 = var3.getSubTableStr();
				String[] var5 = var4.split(",");
				String[] var6 = var5;
				int var7 = var5.length;

				for (int var8 = 0; var8 < var7; ++var8) {
					String var9 = var6[var8];
					OnlCgformHead var10 = this.baseMapper.selectOne(Wrappers.lambdaQuery(OnlCgformHead.class).eq(OnlCgformHead::getTableName, var9));
					if (var10 != null) {
						List var11 = this.fieldService.list(Wrappers.lambdaQuery(OnlCgformField.class).eq(OnlCgformField::getCgformHeadId, var10.getId()));
						String var12 = "";
						String var13 = null;
						Iterator var14 = var11.iterator();

						while (var14.hasNext()) {
							OnlCgformField var15 = (OnlCgformField) var14.next();
							if (!oConvertUtils.isEmpty(var15.getMainField())) {
								var12 = var15.getDbFieldName();
								String var16 = var15.getMainField();
								var13 = json.getString(var16);
							}
						}

						if (!oConvertUtils.isEmpty(var13)) {
							this.fieldService.deleteAutoList(var9, var12, var13);
							String var18 = json.getString("sub-table-design_" + var9);
							if (!oConvertUtils.isEmpty(var18)) {
								JSONArray var19 = JSONArray.parseArray(URLDecoder.decode(var18, "UTF-8"));
								if (var19 != null && var19.size() != 0) {
									for (int var20 = 0; var20 < var19.size(); ++var20) {
										JSONObject var17 = var19.getJSONObject(var20);
										if (var13 != null) {
											var17.put(var12, var13);
										}

										this.fieldService.executeInsertSQL(CgformSqlUtil.parseInsertSql(var9, var11, var17));
									}
								}
							}
						}
					}
				}
			}

			this.fieldService.editFormData(var3.getId(), tbname, json, true);
		}
	}
	@Override
	public Integer getMaxCopyVersion(String physicId) {
		Integer var2 = this.baseMapper.getMaxCopyVersion(physicId);
		return var2 == null ? 0 : var2;
	}
	@Override
	public void copyOnlineTableConfig(OnlCgformHead physicTable) throws Exception {
		String var2 = physicTable.getId();
		int var3 = this.getMaxCopyVersion(var2);
		OnlCgformHead cgformHead = new OnlCgformHead();
		cgformHead.setId(UUIDGenerator.generate());
		cgformHead.setPhysicId(var2);
		cgformHead.setCopyType(1);
		cgformHead.setCopyVersion(physicTable.getTableVersion());
		cgformHead.setTableVersion(1);
		cgformHead.setTableName(physicTable.getTableName() + "$" + var3);
		cgformHead.setTableTxt(physicTable.getTableTxt());
		cgformHead.setFormCategory(physicTable.getFormCategory());
		cgformHead.setFormTemplate(physicTable.getFormTemplate());
		cgformHead.setFormTemplateMobile(physicTable.getFormTemplateMobile());
		cgformHead.setIdSequence(physicTable.getIdSequence());
		cgformHead.setIdType(physicTable.getIdType());
		cgformHead.setIsCheckbox(physicTable.getIsCheckbox());
		cgformHead.setIsPage(physicTable.getIsPage());
		cgformHead.setIsTree(physicTable.getIsTree());
		cgformHead.setQueryMode(physicTable.getQueryMode());
		cgformHead.setTableType(1);
		cgformHead.setIsDbSynch("N");
		cgformHead.setTreeParentIdField(physicTable.getTreeParentIdField());
		cgformHead.setTreeFieldname(physicTable.getTreeFieldname());
		cgformHead.setTreeIdField(physicTable.getTreeIdField());
		cgformHead.setRelationType((Integer) null);
		cgformHead.setTabOrderNum((Integer) null);
		cgformHead.setSubTableStr((String) null);
		cgformHead.setThemeTemplate(physicTable.getThemeTemplate());
		cgformHead.setScroll(physicTable.getScroll());
		List onlCgformFields = this.fieldService.list(Wrappers.lambdaQuery(OnlCgformField.class).eq(OnlCgformField::getCgformHeadId, var2));
		Iterator iterator = onlCgformFields.iterator();
		while (iterator.hasNext()) {
			OnlCgformField var8 = (OnlCgformField) iterator.next();
			OnlCgformField var9 = new OnlCgformField();
			var9.setCgformHeadId(cgformHead.getId());
			this.copyProperties(var8, var9);
			this.fieldService.save(var9);
		}

		this.baseMapper.insert(cgformHead);
	}
	@Override
	public void initCopyState(List<OnlCgformHead> headList) {
		List var2 = this.baseMapper.queryCopyPhysicId();
		Iterator var3 = headList.iterator();

		while (var3.hasNext()) {
			OnlCgformHead var4 = (OnlCgformHead) var3.next();
			if (var2.contains(var4.getId())) {
				var4.setHascopy(1);
			} else {
				var4.setHascopy(0);
			}
		}

	}
	@Override
	public void deleteBatch(String ids, String flag) {
		String[] var3 = ids.split(",");
		if ("1".equals(flag)) {
			String[] var4 = var3;
			int var5 = var3.length;

			for (int var6 = 0; var6 < var5; ++var6) {
				String var7 = var4[var6];

				try {
					this.deleteRecordAndTable(var7);
				} catch (DBException var9) {
					var9.printStackTrace();
				} catch (SQLException var10) {
					var10.printStackTrace();
				}
			}
		} else {
			this.removeByIds(Arrays.asList(var3));
		}

	}
	@Override
	public void updateParentNode(OnlCgformHead head, String dataId) {
		if ("Y".equals(head.getIsTree())) {
			String var3 = CgformSqlUtil.parsePattern(head.getTableName());
			String var4 = head.getTreeParentIdField();
			Map var5 = this.baseMapper.queryOneByTableNameAndId(var3, dataId);
			String var6 = null;
			if (var5.get(var4) != null && !"0".equals(var5.get(var4))) {
				var6 = var5.get(var4).toString();
			} else if (var5.get(var4.toUpperCase()) != null && !"0".equals(var5.get(var4.toUpperCase()))) {
				var6 = var5.get(var4.toUpperCase()).toString();
			}

			if (var6 != null) {
				Integer var7 = this.baseMapper.queryChildNode(var3, var4, var6);
				if (var7 == 1) {
					String var8 = head.getTreeIdField();
					this.fieldService.updateTreeNodeNoChild(var3, var8, var6);
				}
			}
		}

	}

	private void b(OnlCgformHead var1, List<OnlCgformField> var2) {
		List var3 = this.list(Wrappers.lambdaQuery(OnlCgformHead.class).eq(OnlCgformHead::getPhysicId, var1.getId()));
		if (var3 != null && var3.size() > 0) {
			Iterator var4 = var3.iterator();

			while (true) {
				List var6;
				String var13;
				ArrayList var19;
				Iterator var22;
				label108:
				do {
					while (var4.hasNext()) {
						OnlCgformHead var5 = (OnlCgformHead) var4.next();
						var6 = this.fieldService.list(Wrappers.lambdaQuery(OnlCgformField.class).eq(OnlCgformField::getCgformHeadId, var5.getId()));
						OnlCgformField var9;
						if (var6 != null && var6.size() != 0) {
							HashMap var15 = new HashMap();
							Iterator var16 = var6.iterator();

							while (var16.hasNext()) {
								var9 = (OnlCgformField) var16.next();
								var15.put(var9.getDbFieldName(), 1);
							}

							HashMap var17 = new HashMap();
							Iterator var18 = var2.iterator();

							while (var18.hasNext()) {
								OnlCgformField var10 = (OnlCgformField) var18.next();
								var17.put(var10.getDbFieldName(), 1);
							}

							var19 = new ArrayList();
							ArrayList var20 = new ArrayList();
							Iterator var11 = var17.keySet().iterator();

							while (var11.hasNext()) {
								String var12 = (String) var11.next();
								if (var15.get(var12) == null) {
									var20.add(var12);
								} else {
									var19.add(var12);
								}
							}

							ArrayList var21 = new ArrayList();
							var22 = var15.keySet().iterator();

							while (var22.hasNext()) {
								var13 = (String) var22.next();
								if (var17.get(var13) == null) {
									var21.add(var13);
								}
							}

							OnlCgformField var23;
							if (var21.size() > 0) {
								var22 = var6.iterator();

								while (var22.hasNext()) {
									var23 = (OnlCgformField) var22.next();
									if (var21.contains(var23.getDbFieldName())) {
										this.fieldService.removeById(var23.getId());
									}
								}
							}

							if (var20.size() > 0) {
								var22 = var2.iterator();

								while (var22.hasNext()) {
									var23 = (OnlCgformField) var22.next();
									if (var20.contains(var23.getDbFieldName())) {
										OnlCgformField var14 = new OnlCgformField();
										var14.setCgformHeadId(var5.getId());
										this.copyProperties(var23, var14);
										this.fieldService.save(var14);
									}
								}
							}
							continue label108;
						}

						Iterator var7 = var2.iterator();

						while (var7.hasNext()) {
							OnlCgformField var8 = (OnlCgformField) var7.next();
							var9 = new OnlCgformField();
							var9.setCgformHeadId(var5.getId());
							this.copyProperties(var8, var9);
							this.fieldService.save(var9);
						}
					}

					return;
				} while (var19.size() <= 0);

				var22 = var19.iterator();

				while (var22.hasNext()) {
					var13 = (String) var22.next();
					this.b(var13, var2, var6);
				}
			}
		}
	}

	private void b(String var1, List<OnlCgformField> var2, List<OnlCgformField> var3) {
		OnlCgformField var4 = null;
		Iterator var5 = var2.iterator();

		while (var5.hasNext()) {
			OnlCgformField var6 = (OnlCgformField) var5.next();
			if (var1.equals(var6.getDbFieldName())) {
				var4 = var6;
			}
		}

		OnlCgformField var8 = null;
		Iterator var9 = var3.iterator();

		while (var9.hasNext()) {
			OnlCgformField var7 = (OnlCgformField) var9.next();
			if (var1.equals(var7.getDbFieldName())) {
				var8 = var7;
			}
		}

		if (var4 != null && var8 != null) {
			boolean var10 = false;
			if (!var4.getDbType().equals(var8.getDbType())) {
				var8.setDbType(var4.getDbType());
				var10 = true;
			}

			if (!var4.getDbDefaultVal().equals(var8.getDbDefaultVal())) {
				var8.setDbDefaultVal(var4.getDbDefaultVal());
				var10 = true;
			}

			if (!var4.getDbLength().equals(var8.getDbLength())) {
				var8.setDbLength(var4.getDbLength());
				var10 = true;
			}

			if (!var4.getDbIsNull().equals(var8.getDbIsNull())) {
				var8.setDbIsNull(var4.getDbIsNull());
				var10 = true;
			}

			if (var10) {
				this.fieldService.updateById(var8);
			}
		}

	}

	private void copyProperties(OnlCgformField source, OnlCgformField dist) {
		dist.setDbDefaultVal(source.getDbDefaultVal());
		dist.setDbFieldName(source.getDbFieldName());
		dist.setDbFieldNameOld(source.getDbFieldNameOld());
		dist.setDbFieldTxt(source.getDbFieldTxt());
		dist.setDbIsKey(source.getDbIsKey());
		dist.setDbIsNull(source.getDbIsNull());
		dist.setDbLength(source.getDbLength());
		dist.setDbPointLength(source.getDbPointLength());
		dist.setDbType(source.getDbType());
		dist.setDictField(source.getDictField());
		dist.setDictTable(source.getDictTable());
		dist.setDictText(source.getDictText());
		dist.setFieldExtendJson(source.getFieldExtendJson());
		dist.setFieldHref(source.getFieldHref());
		dist.setFieldLength(source.getFieldLength());
		dist.setFieldMustInput(source.getFieldMustInput());
		dist.setFieldShowType(source.getFieldShowType());
		dist.setFieldValidType(source.getFieldValidType());
		dist.setFieldDefaultValue(source.getFieldDefaultValue());
		dist.setIsQuery(source.getIsQuery());
		dist.setIsShowForm(source.getIsShowForm());
		dist.setIsShowList(source.getIsShowList());
		dist.setMainField((String) null);
		dist.setMainTable((String) null);
		dist.setOrderNum(source.getOrderNum());
		dist.setQueryMode(source.getQueryMode());
		dist.setIsReadOnly(source.getIsReadOnly());
		dist.setSortFlag(source.getSortFlag());
		dist.setQueryDefVal(source.getQueryDefVal());
		dist.setQueryConfigFlag(source.getQueryConfigFlag());
		dist.setQueryDictField(source.getQueryDictField());
		dist.setQueryDictTable(source.getQueryDictTable());
		dist.setQueryDictText(source.getQueryDictText());
		dist.setQueryMustInput(source.getQueryMustInput());
		dist.setQueryShowType(source.getQueryShowType());
		dist.setQueryValidType(source.getQueryValidType());
		dist.setConverter(source.getConverter());
	}

	private void setLength(OnlCgformField var1) {
		if ("Text".equals(var1.getDbType()) || "Blob".equals(var1.getDbType())) {
			var1.setDbLength(0);
			var1.setDbPointLength(0);
		}

	}
}
